home *** CD-ROM | disk | FTP | other *** search
/ Aminet 33 / Aminet 33 - October 1999.iso / Aminet / dev / gui / ClassFree_src.lha / ClassFree_src / CFscrollerclass / class_lib.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-09-02  |  2.5 KB  |  121 lines

  1. /* Library replacement routines */
  2.  
  3. #include <exec/libraries.h>
  4. #include <proto/exec.h>
  5. #include <intuition/classes.h>
  6. #include <dos/dos.h>
  7. #include "class.h"
  8.  
  9. #pragma libbase classbase  /* So StormCs linker knows the libbase size.. */
  10.  
  11. extern struct ExecBase *SysBase;
  12. struct Library *IntuitionBase;
  13. struct Library *UtilityBase;
  14. struct Library *GfxBase;
  15. struct Library *btnbase;
  16. #ifdef DEBUG
  17.  #include "debug_protos.h"
  18.  APTR console;
  19. #endif
  20.  
  21. BPTR LibExpunge();
  22. BOOL openlibs(void);
  23. void closelibs(void);
  24.  
  25. struct classbase *LibInit(
  26.         register __d0 struct classbase *base,
  27.         register __a0 BPTR seglist,
  28.         register __a6 APTR sysbase)
  29. {
  30.   base->seglist = seglist;
  31.   SysBase = sysbase;
  32.   if(openlibs()) return(base);
  33.   return(NULL);
  34. }
  35.  
  36. struct Library *LibOpen(register __a6 struct classbase *base)
  37. {
  38.   if(!(base->library.lib_OpenCnt)) initclass(base);
  39.   base->library.lib_Flags &= ~LIBF_DELEXP;
  40.   base->library.lib_OpenCnt++;
  41.   return((struct Library *)base);
  42. }
  43.  
  44. BPTR LibClose(register __a6 struct classbase *base)
  45. {
  46.   base->library.lib_OpenCnt--;
  47.   if(!base->library.lib_OpenCnt)
  48.     if(base->library.lib_Flags&LIBF_DELEXP) return(LibExpunge());
  49.   return(NULL);
  50. }
  51.  
  52. BPTR LibExpunge(register __a6 struct classbase *base)
  53. {
  54.   BPTR result;
  55.   UBYTE *libmem;
  56.   LONG libsize;
  57.  
  58.   if(base->library.lib_OpenCnt)
  59.   {
  60.     base->library.lib_Flags |= LIBF_DELEXP;
  61.     return(NULL)
  62.   }
  63.   else
  64.   {
  65.     result = base->seglist;
  66.     Remove((struct Node *)base);
  67.     closelibs();
  68.     removeclass(base);
  69.     libmem = (UBYTE *)base;
  70.     libsize = base->library.lib_NegSize;
  71.     libmem -= libsize;
  72.     libsize += base->library.lib_PosSize;
  73.     FreeMem(libmem,libsize);
  74.     return(result);
  75.   }
  76. }
  77.  
  78. ULONG LibNull(void)
  79. {
  80.   return(NULL);
  81. }
  82.  
  83. BOOL openlibs(void)
  84. {
  85.   IntuitionBase = OpenLibrary("intuition.library",37);
  86.   UtilityBase = OpenLibrary("utility.library",37);
  87.   GfxBase = OpenLibrary("graphics.library",37);
  88.   if(!(btnbase = OpenLibrary("CFbutton.gadget",0)))
  89.     btnbase = OpenLibrary("Gadgets/CFbutton.gadget",0);
  90. #ifdef DEBUG
  91.   console = DLopencon();
  92. #endif
  93.   if(IntuitionBase&&UtilityBase&&GfxBase&&btnbase) return(TRUE);
  94.   closelibs();
  95.   return(FALSE);
  96. }
  97.  
  98. void closelibs(void)
  99. {
  100. #ifdef DEBUG
  101.   DLclosecon(console);
  102. #endif
  103.   CloseLibrary(btnbase);
  104.   CloseLibrary(GfxBase);
  105.   CloseLibrary(UtilityBase);
  106.   CloseLibrary(IntuitionBase);
  107. }
  108.  
  109. /* This function converts register-parameter hook calling
  110.  * convention into standard C conventions.
  111.  */
  112. ULONG hookEntry(
  113.     register __a0 struct Hook *h,
  114.     register __a2 VOID *o,
  115.     register __a1 VOID *msg)
  116. {
  117.     return ((*h->h_SubEntry)(h, o, msg));
  118. }
  119.  
  120.  
  121.